home *** CD-ROM | disk | FTP | other *** search
- // main.c
-
- #include "main.h"
-
- static void DoTest(void);
- static void DoInit(void);
- static void DoLoop(void);
- static void DoExit(void);
- static void DoMenuItem(long theMenuAndItem);
- static void DisplayScrapColorInfo(void);
- static void DrawColorString(short model, unsigned short value, short index);
- static void PutColorPickerIntoScrap(unsigned short model);
-
- static Boolean gDone = FALSE;
- static short gScrapCount = -1;
-
- void DoTest()
- {
-
- }
-
- void DoInit(void)
- {
- MaxApplZone();
- MoreMasters();
-
- // Basic Initialization
- InitGraf(&qd.thePort);
-
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0);
- InitCursor();
-
- InsertMenu(GetMenu(kAppleMenuID), 0);
- AddResMenu(GetMHandle(kAppleMenuID), 'DRVR');
- InsertMenu(GetMenu(kFileMenuID), 0);
- InsertMenu(GetMenu(kEditMenuID), 0);
- DrawMenuBar();
-
- {
- Rect aRect;
- SetRect(&aRect,50,50,400,150);
- NewWindow(NULL,&aRect,"\pScrap Color",TRUE,0,(WindowPtr)-1,FALSE,0L);
- }
-
- }
-
- void PutColorPickerIntoScrap(unsigned short model)
- {
- RGBColor rgbColor;
- ColorData theColor;
- Point pt;
-
- pt.h = pt.v = 0;
- rgbColor.red = rgbColor.green = rgbColor.blue = 0;
- GetColor(pt,"\pPick a color:",&rgbColor,&rgbColor);
-
- ConvertColor((ColorData*)&rgbColor,kRGBModel,&theColor,model);
- ZeroScrap();
- PutColorIntoScrap(&theColor,model);
- }
-
- void DrawColorString(short model, unsigned short value, short index)
- {
- double dpercent;
- unsigned short percent;
- Str255 numString;
-
- if ((model == kHSVModel || model == kHSLModel) && index == 1 && value == 0)
- {
- DrawString("\pundef");
- return;
- }
-
- dpercent = ((double)value / (double)65535);
- if ((model == kHSVModel || model == kHSLModel) && index == 1)
- {
- percent = 360 * dpercent;
- NumToString(percent,numString);
- numString[0]++;
- numString[numString[0]] = '°';
- }
- else
- {
- percent = 100 * dpercent;
- NumToString(percent,numString);
- numString[0]++;
- numString[numString[0]] = '%';
- }
-
- DrawString(numString);
- }
-
- void DisplayScrapColorInfo(void)
- {
- WindowPtr theWindow;
- ColorData data;
- short model;
- Str255 theStr;
- short x, strIndex;
- Rect aRect;
-
-
- theWindow = FrontWindow();
- SetPort(theWindow);
- TextFont(monaco);
- TextSize(12);
- TextFace(0);
- aRect = theWindow->portRect;
- EraseRect(&aRect);
- if (!GetColorFromScrap(&data,&model))
- {
- strIndex = 128 + model;
-
- for (x = 1; x < 4; x++)
- {
- MoveTo(5,12*x);
- GetIndString(theStr,strIndex,x);
- DrawString(theStr);
- Move(5,0);
- // treat data as an array of unsigned shorts
- DrawColorString(model,((unsigned short*)&data)[x-1],x);
- }
- }
- }
-
- void DoLoop(void)
- {
- EventRecord theEvent;
-
- while(!gDone)
- {
- PScrapStuff scrapInfo;
-
- scrapInfo = InfoScrap();
- if (scrapInfo->scrapCount != gScrapCount)
- {
- gScrapCount = scrapInfo->scrapCount;
- DisplayScrapColorInfo();
- }
-
- WaitNextEvent(everyEvent, &theEvent, 30, 0); // Sleep for 2.5 secs
-
- switch(theEvent.what)
- {
- case nullEvent:
- break;
-
- case mouseDown:
- {
- short thePart;
- WindowPtr whichWin;
-
- thePart = FindWindow(theEvent.where, &whichWin);
-
- switch(thePart)
- {
- case inMenuBar:
- DoMenuItem(MenuSelect(theEvent.where));
- break;
-
- case inSysWindow:
- SystemClick(&theEvent, whichWin);
- break;
-
- case inDrag:
- {
- Rect bounds;
-
- bounds = (*GetGrayRgn())->rgnBBox;
- DragWindow(whichWin, theEvent.where, &bounds);
- }
- break;
- }
- }
- break;
-
- case keyDown:
- case autoKey:
- if (theEvent.modifiers & cmdKey)
- DoMenuItem(MenuKey(theEvent.message & charCodeMask));
- break;
- case updateEvt:
- break;
- case activateEvt:
- break;
- case kHighLevelEvent:
- break;
- }
- }
- }
-
- void DoMenuItem(long theMenuAndItem)
- {
- short theMenu, theItem;
- Str63 theString;
-
- if (! theMenuAndItem) return;
-
- theMenu = (theMenuAndItem & 0xFFFF0000) >> 16;
- theItem = theMenuAndItem & 0x0000FFFF;
-
- switch(theMenu) {
- case kAppleMenuID:
- switch (theItem)
- {
- default:
- {
- GetItem(GetMHandle(theMenu), theItem, theString);
- OpenDeskAcc(theString);
- }
- break;
- }
- break;
-
- case kFileMenuID:
- switch(theItem)
- {
- case kFileMenuQuitItem:
- gDone = TRUE;
- break;
- }
- break;
-
- case kEditMenuID:
- switch(theItem)
- {
- case kEditMenuCutItem:
- break;
-
- case kEditMenuCopyItem:
- break;
-
- case kEditMenuPasteItem:
- break;
-
- case kEditMenuPutColorItem:
- PutColorPickerIntoScrap(kRGBModel);
- break;
- }
- break;
-
- default:
- break;
- }
- HiliteMenu(0);
- DrawMenuBar();
- }
-
- void DoExit(void)
- {
-
- }
-
- void main()
- {
- DoTest();
- DoInit();
- DoLoop();
- DoExit();
- }
-
-